package cn.tedu.hospitalgroupproject.server.content.service.impl;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.IAppointmentRepository;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.impl.AppointmentRepositoryImpl;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.Appointment;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.AppointmentAddNewParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.AppointmentListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.ClinicListVO;
import cn.tedu.hospitalgroupproject.server.content.service.IAppointmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


/**
 * 处理预约挂号数据的业务实现类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Service
@Slf4j
public class AppointmentServiceImpl implements IAppointmentService {

    @Value("${hospital-appointment.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;

    @Autowired
    private IAppointmentRepository appointmentRepository;


    public AppointmentServiceImpl() {
        log.info("创建业务对象:AppointmentServiceImpl");
    }

    @Override
    public void addNew(AppointmentAddNewParam appointmentAddNewParam) {
        log.debug("开始处理[新增预约挂号单]的业务,参数:{}",appointmentAddNewParam);

        Appointment appointment=new Appointment();
        BeanUtils.copyProperties(appointmentAddNewParam,appointment);

        appointmentRepository.insert(appointment);
    }

    @Override
    public PageData<AppointmentListVO> listByVisitTime(Integer pageNum, String visitTime) {
        log.debug("开始处理【根据问诊时间查询预约单列表】业务，页码：{},问诊时间:{}", pageNum,visitTime);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByVisitTime(pageNum, defaultQueryPageSize,visitTime);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> listByVisitTime(Integer pageNum, Integer pageSize, String visitTime) {
        log.debug("开始处理【根据问诊时间查询预约单列表】业务，页码：{},问诊时间:{}", pageNum,visitTime);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByVisitTime(pageNum, pageSize,visitTime);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> listByCreateTime(Integer pageNum, String createTime) {
        log.debug("开始处理【根据预约时间查询预约单列表】业务，页码：{},预约创建时间:{}", pageNum,createTime);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByCreateTime(pageNum, defaultQueryPageSize,createTime);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> listByCreateTime(Integer pageNum, Integer pageSize, String createTime) {
        log.debug("开始处理【根据预约时间查询预约单列表】业务，页码：{},预约创建时间:{}", pageNum,createTime);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByCreateTime(pageNum, pageSize,createTime);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> listByDoctorName(Integer pageNum, String doctorName) {
        log.debug("开始处理【根据医生姓名查询预约单列表】业务，页码：{},医生姓名:{}", pageNum,doctorName);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByDoctorName(pageNum, defaultQueryPageSize,doctorName);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> listByDoctorName(Integer pageNum, Integer pageSize, String doctorName) {
        log.debug("开始处理【根据医生姓名查询预约单列表】业务，页码：{},预约创建时间:{}", pageNum,doctorName);
        PageData<AppointmentListVO> pageData = appointmentRepository.listByDoctorName(pageNum, pageSize,doctorName);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> list(Integer pageNum) {
        log.debug("开始处理【查询预约单列表】业务，页码：{}", pageNum);
        PageData<AppointmentListVO> pageData = appointmentRepository.list(pageNum, defaultQueryPageSize);
        return pageData;
    }

    @Override
    public PageData<AppointmentListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始处理【查询预约单列表】业务，页码：{}", pageNum);
        PageData<AppointmentListVO> pageData = appointmentRepository.list(pageNum, pageSize);
        return pageData;
    }
}
